try:
    import pyi_splash
    pyi_splash.close()
except:
    pass

import sys
import tkinter as tk
from tkinter import *
from turtle import st
import pyautogui
from pywin import *
import win32gui
import win32con
import win32api

pyautogui.PAUSE = 0
pyautogui.FAILSAFE = False

run = True

sx, sy = pyautogui.size()

root = Tk()
root.geometry("160x120")
root.protocol("WM_DELETE_WINDOW", lambda: stopper())
root.resizable(False, False)
root.attributes("-topmost", True)
root.attributes("-alpha", 1)

usev = BooleanVar()
usev.set(True)
use = Checkbutton(root, text="使用", font=("华文楷体", 30), variable=usev, onvalue=True, offvalue=False, indicatoron=False, activebackground="#4466FF", activeforeground="#FFFFFF")
use.place(x=0, y=0, width=160, height=80)
stop = Button(root, text="停止", font=("华文楷体", 20), command=lambda: stopper(), bg="#FF0000", fg="#FFFFFF")
stop.place(x=0, y=80, width=160, height=40)

def stopper(): 
    global run
    usev.set(False)
    root.destroy()
    run = False

tp_x = [0, sx-1]
tp_y = [0, sy-1]
print(win32api.GetCursorPos())

def bytp():
    mouse_x, mouse_y = win32api.GetCursorPos()
    move = False
    #tp_x = [0, sb[2]-sb[0]-1]
    #tp_y = [0, sb[3]-sb[1]-1]
    if mouse_x <= tp_x[0]:
        mouse_x = tp_x[1]-1
        move = True
    elif mouse_x >= tp_x[1]:
        mouse_x = tp_x[0]+1
        move = True
    if mouse_y <= tp_y[0]:    
        mouse_y = tp_y[1]-1
        move = True
    elif mouse_y >= tp_y[1]:
        mouse_y = tp_y[0]+1
        move = True
    if move:
        win32api.SetCursorPos((mouse_x, mouse_y))

while run:
    root.update()
    while usev.get():
        root.update()
        bytp()
        if not run:
            break

exit()
